package pref.junx.flybird.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import pref.junx.flybird.R;
import pref.junx.flybird.activity.grou_msg.Grou_msg_Actvity;
import pref.junx.flybird.entity.Group;
import pref.junx.flybird.util.ExpandableViewHoldersUtil;

/**
 * Created by JunX on 17/5/13.
 */

public class SimpleAdapter_gro extends RecyclerView.Adapter<SimpleAdapter_gro.SimpleViewHolder> {

    private List<Group> data;
    private Context context;


    public SimpleAdapter_gro(Context context, List<Group> data) {

        this.context = context;
        this.data = data;

    }

    @Override
    public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_simple_group, parent, false);
        SimpleViewHolder holder = new SimpleViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SimpleViewHolder holder, int position) {
        holder.bind(position);
        holder.nick.setText(data.get(position).getGroup_name());
        if(position%2==0){
            holder.nick.setTextColor(ContextCompat.getColor(context,R.color.black));
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class SimpleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, ExpandableViewHoldersUtil.Expandable, ExpandableViewHoldersUtil.ExpandableTop {

        LinearLayout submit_view;
        RelativeLayout top_view;
        TextView nick;
        TextView more;



        public SimpleViewHolder(View view) {
            super(view);
            view.setOnClickListener(this);
            more=(TextView) view.findViewById(R.id.group_more);
            nick=(TextView) view.findViewById(R.id.group_name);
           more.setOnClickListener(this);
        }



        @Override
        public void onClick(View v) {
                switch (v.getId()){
                    case R.id.group_more:
                        Intent intent = new Intent();
                        intent.setClass(context, Grou_msg_Actvity.class);
                        intent.putExtra("id",data.get(getAdapterPosition()).getGroup_id());
                        intent.putExtra("name",data.get(getAdapterPosition()).getGroup_name());
                        intent.putExtra("value",data.get(getAdapterPosition()).getGroup_calue());
                        context.startActivity(intent);
                }
        }

        public void bind(int pos) {


        }

        @Override
        public View getExpandView() {
            return submit_view;
        }

        @Override
        public View getExpandTopView() {
            return top_view;
        }
    }

}
